home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 October: Technology Seed / ADC Seed CD - October 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / BevelDialog.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  5.0 KB  |  192 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        BevelDialog.cp
  3.  
  4.     Contains:    Bevel Button examples dialog.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (MAA)    Matt Ackeret
  21.         (edv)    Ed Voas
  22.  
  23.     Change History (most recent first):
  24.  
  25.          <2>     3/16/98    MAA        change GetDialogItems to GetDialogItemAsControls
  26.          <1>     9/11/97    edv        First checked in.
  27. */
  28.  
  29. //
  30. //    This file implements a simple dialog which shows a myriad of bevel
  31. //    button possibilities. Even with all it shows, it does not show all
  32. //    the possible variations.
  33. //
  34.  
  35. #include "AppearanceSamplePrefix.h"
  36.  
  37. #include <Appearance.h>
  38. #include <Folders.h>
  39. #include <Fonts.h>
  40. #include <Controls.h>
  41. #include <Icons.h>  // ÄÄÄ TEMP MAA
  42. #include "BevelDialog.h"
  43. #include "AppearanceHelpers.h"
  44.  
  45. void    HandleBevelDialog( DialogPtr dialog, short itemHit );
  46.  
  47. void    EnableDisableAll( DialogPtr dialog, Boolean enable );
  48. void    SetControlValues( DialogPtr dialog, short value );
  49. void    SetUpBevelDialog( DialogPtr dialog );
  50.  
  51.  
  52. enum {
  53.     kDisableButton        = 1,
  54.     kEnableButton        = 2,
  55.     kOnButton            = 3,
  56.     kOffButton            = 4,
  57.     kMixedButton        = 5,
  58.     kFirstButton         = 6,
  59.     kLastButton         = 32
  60. };
  61.  
  62. BevelDialog::BevelDialog() : BaseDialog( 1001 )
  63. {
  64.     GrafPtr            savePort;
  65.     ControlHandle    control;
  66.     
  67.     if ( fWindow )
  68.     {
  69.         GetPort( &savePort );
  70.         SetPort( fPort );
  71.         TextFont( applFont );
  72.         TextSize( 10 );
  73.         SetPort( savePort );
  74.  
  75.  
  76.             // This next bit of code sets one of our bevel buttons up to
  77.             // make the text always appear 0 pixels from the edge in an
  78.             // internationalized fashion, i.e. in left-to-right scripts
  79.             // it will be placed starting 0 pixels from the left.
  80.             // In right-to-left scripts it will be 0 pixels in from the
  81.             // right.
  82.             
  83.         GetDialogItemAsControl( fDialog, 18, &control );    
  84.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 0 );
  85.         GetDialogItemAsControl( fDialog, 19, &control );    
  86.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 0 );
  87.         GetDialogItemAsControl( fDialog, 20, &control );    
  88.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushRight, 0 );
  89.         GetDialogItemAsControl( fDialog, 21, &control );    
  90.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 5 );
  91.  
  92.             // This code sets up some of the buttons to align the text
  93.             // and graphics so they fit together side by side (or above
  94.             // each other).
  95.             
  96.         GetDialogItemAsControl( fDialog, 26, &control );
  97.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToRightOfGraphic );
  98.         GetDialogItemAsControl( fDialog, 27, &control );
  99.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToLeftOfGraphic );
  100.         GetDialogItemAsControl( fDialog, 28, &control );
  101.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceBelowGraphic );
  102.         GetDialogItemAsControl( fDialog, 29, &control );
  103.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceAboveGraphic );
  104.         GetDialogItemAsControl( fDialog, 30, &control );
  105.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceSysDirection );
  106.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignSysDirection, 0, 0 );
  107.  
  108.         GetDialogItemAsControl( fDialog, 31, &control );
  109.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToRightOfGraphic );
  110.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignLeft, 2, 0 );
  111.  
  112.         GetDialogItemAsControl( fDialog, 32, &control );
  113.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToLeftOfGraphic );
  114.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignRight, 2, 0 );
  115.  
  116.         // ÄĆMAA TEMPORARY CODE
  117.         IconRef theIconRef;
  118.         
  119.         GetIconRef( kOnSystemDisk, kSystemIconsCreator, kGenericFloppyIcon, &theIconRef );
  120.         if (theIconRef)
  121.         {
  122.             MenuHandle theMenuHandle = GetMenu(131);
  123.  
  124.             if (theMenuHandle)
  125.                 SetMenuItemIconHandle(theMenuHandle, 1, kMenuIconRefType, (Handle)theIconRef);
  126.             else
  127.                 DebugStr("\pGot no menu handle.");
  128.         }
  129.         else
  130.             DebugStr("\pgot nil IconRef");
  131.  
  132.         ShowWindow( fWindow );
  133.     }
  134. }
  135.  
  136. BevelDialog::~BevelDialog()
  137. {
  138. }
  139.  
  140. void
  141. BevelDialog::HandleItemHit( short itemHit )
  142. {
  143.     switch ( itemHit ) {
  144.         case kDisableButton:
  145.             EnableDisableAll( false );
  146.             break;
  147.         
  148.         case kEnableButton:
  149.             EnableDisableAll( true );
  150.             break;
  151.         
  152.         case kOnButton:
  153.             SetControlValues( kControlCheckBoxCheckedValue );
  154.             break;
  155.         
  156.         case kOffButton:
  157.             SetControlValues( kControlCheckBoxUncheckedValue );
  158.             break;
  159.         
  160.         case kMixedButton:
  161.             SetControlValues( kControlCheckBoxMixedValue );
  162.             break;
  163.             
  164.     }
  165. }
  166.  
  167. void
  168. BevelDialog::EnableDisableAll( Boolean enable )
  169. {
  170.     ControlHandle control;
  171.     short        i;
  172.     
  173.     for ( i = kFirstButton; i <= kLastButton; i++ )
  174.     {
  175.         GetDialogItemAsControl( fDialog, i, &control);
  176.         HiliteControl( control, enable ? 0 : kControlInactivePart );
  177.     }
  178. }
  179.  
  180. void
  181. BevelDialog::SetControlValues( short value )
  182. {
  183.     ControlHandle control;
  184.     short        i;
  185.     
  186.     for ( i = kFirstButton; i <= kLastButton; i++ )
  187.     {
  188.         GetDialogItemAsControl( fDialog, i, &control);
  189.         SetControlValue( control, value );
  190.     }
  191. }
  192.